package linwen.wang.exception.service.impl;


import linwen.wang.exception.commom.ResultVO;
import linwen.wang.exception.exception.BizException;
import linwen.wang.exception.service.User;
import linwen.wang.exception.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName UserServiecImpl
 * @Description
 * @Author lin
 * @Date 2022/3/27 下午11:43
 * @Version V1.0
 */
@Service
@Slf4j
public class UserServiecImpl implements UserService {
    static ArrayList<User> list;

    static {
         list = new ArrayList<User>();
        list.add(User.builder().id("001").name("张三").ag(18).gender("男").address("深圳市").build());

    }
    @Override
    public ResultVO getUserById(String id) {
        List<User> users = list.stream().filter(user -> user.getId().equals(id)).limit(1).collect(Collectors.toList());
        log.info("current user:{}",users);
        if(users.isEmpty()){
            throw new BizException("用户id异常");
        }
        return ResultVO.buildSuccessResultVO(users.get(0));
    }
}
